/*HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 H       semaphore.h
 H       Application name: tcss422-project2
 H       Programmers names:	Evan Phillips, Lucas Cowell, Tony Butterfield
 H       Date created:	May 28, 2011
 H       Date completed:
 H       Brief Description: Simulate a semaphore by managing owner and blocked queue.
 H
 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH*/

#ifndef SEMAPHORE_H_
#define SEMAPHORE_H_
#endif /* SEMAPHORE_H_ */

/* FORWARD DEFINITIONS - resolves circular dependencies */
struct cpu_str;
struct process_queue_str;
struct process_str;

/***************************************************************************************************
 *  ADT: Semaphore
 *  Description: A simulation of a semaphore. The semaphore is a standalone object that can be used
 *  			 to protect an arbritary memory location or variable.
 *
 *
 *  Implementation: Contains a pointer for the process that currently owns the semaphore, and uses a
 *  				process queue to simulate a blocked queue.
 *
 *
 ***************************************************************************************************/

/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 $ Typedefs
 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
typedef struct semaphore_str
{
	struct process_str* owner;
	struct process_queue_str* blocked_q;    // this devices blocked process queue
} SemaphoreStr;
typedef SemaphoreStr* Semaphore;

/*-------------------------------------------------------------------------------------------------
 - Prototypes
 -      Initialize - create an new semaphore.
 -      Terminate - deallocates memory allocated in Initialize.
 -		Down - Request ownership of this semaphore
 -		Up - Release ownership of this semaphore
 -
 ---------------------------------------------------------------------------------------------------*/
Semaphore   semaphore_init(); 							// allocate memory for owner and ProcessQueue
int         semaphore_free(Semaphore);                	// deallocate mem.
int         semaphore_down(Semaphore, Process);         // set owner or add to blocked queue
int         semaphore_up(Semaphore, Process);         	// release ownership of semaphore
